<template>
  <div class="progress-circle-wrap">
    <svg
      :width="radius"
      :height="radius"
      viewBox="0 0 100 100"
      xmlns="http://www.w3.org/2000/svg"
      version="1.1"
      >
      <circle class="progress-bg" cx="50" cy="50" r="50" fill="transparent" />
      <circle class="progress-bar" cx="50" cy="50" r="50" fill="transparent"
              :stroke-dasharray="dasharray"
              :stroke-dashoffset="dashoffset"
       />
    </svg>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'progress-circle',
  props: {
    // 圆环大小
    radius: {
      type: Number,
      default: 28
    },
    percent: {
      type: Number,
      default: 0.5
    }
  },
  data () {
    return {
      dasharray: Math.PI * 100 // 由 circle 上的 r="50" 计算而来
    }
  },
  computed: {
    dashoffset () {
      return (1 - this.percent) * this.dasharray
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~common/stylus/variable.styl'
  .progress-circle-wrap {
    position: relative
    margin-right: 14px
    circle {
      stroke-width: 8px
      transform-origin: center
      &.progress-bar {
        stroke: $color-theme
        transform: scale(0.9) rotate(-90deg)
      }
      &.progress-bg {
        stroke: $color-theme-d
        transform: scale(0.9)
      }
    }
  }
</style>
